import 'package:flutter/material.dart';

class CounterWidget extends StatefulWidget {

  const CounterWidget({super.key, this.initValue =0});

  final int initValue;


  @override
  State<StatefulWidget> createState() => _CounterWidgetState();

}
class _CounterWidgetState extends State<CounterWidget> {

  late int _counter;

  @override
  void initState() {
    super.initState();

    //初始化状态
    _counter = widget.initValue;
    print("initState");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: TextButton(
          child: Text('$_counter'),
          onPressed:() => setState(()=> ++_counter),
        ),
      ),
    );
  }

  @override
  void didUpdateWidget(covariant CounterWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    print("didUpdateWidget");
  }

  @override
  void deactivate() {
    super.deactivate();
    print("deactivate");
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("reassemble");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("didChangeDependencies");
  }
}